<?php
namespace Project_725;

use TwinPeaks\Core as Core;
use Project_725\View\Frontend as View;
use TwinPeaks\Core\CRule;

class FC_Frontend extends Core\CFrontController
{
	const INDEX_RID = 1;
	const CONFIRM_EMAIL = 2;
	const ABOUT_US_RID = 3;
	const DOWNLOAD_APP_RID = 4;
	
	protected function defineIndexRules()
	{
		CRule::setDefaultController('Controller\Index');		
		
		$this->addRule(CRule::matchStr('/', 'frontend', self::INDEX_RID));
		
		$this->addRule(CRule::matchStr('/about_us/', 'aboutUs', self::ABOUT_US_RID));
		
		$this->addRule(CRule::matchRegexp('/signup/confirm/([^/]+)/?', 'confirmEmail', self::CONFIRM_EMAIL))
			->setURIGetter(function($code) {
				return $this->URI->setPath(sprintf('/signup/confirm/%s/', $code));
			});
			
		$this->addRule(CRule::matchRegexp('/app/love_meter/download/([^/]+)/?', 'appDownload', self::CONFIRM_EMAIL))
			->setURIGetter(function($code) {
				return $this->URI->setPath(sprintf('/app/love_meter/download/%s/', $code));
			});
	}

	protected function defineRules()
	{
		$this->defineIndexRules();
	}
	
	/**
	 * @return void
	 */
	function onSelect()
	{
		$app = self::getApplication();
		$app->definePathAlias('template', '@A/View/Frontend/Template');
		$app->definePathAlias('mockdata', '@A/View/Frontend/MockData');
	}

	function createPageLayout()
	{
		return View\Layout::getInstance();
	}
}
